import React, { Component } from 'react';
import { WingBlank, WhiteSpace, Card, List, InputItem, Button, Toast } from 'antd-mobile';
import './login.less';
import { login } from './api/user'
import {
    withRouter
} from 'react-router-dom';
class Login extends Component{
    constructor(props){
        super(props)
        this.state = {
            form:{
                userName:'',
                passWord:''
            }
        }
        this.submitLogin = this.submitLogin.bind(this)
        this.handleChange = this.handleChange.bind(this)
    }
    //生命周期函数，组件第一次被渲染到Dom中，mount(挂载)
    componentDidMount() {
        console.log("/props",this.props)
    }
    submitLogin(){
        login(this.state.form).then((res) => {
            console.log("res",res)
            if(res){
                console.log("res",res.data.code)
                Toast.success('Login success !!!', 1);
                this.props.history.push('/myhome');
            }

        })
    }   
    handleChange(key,val){
        let form = this.state.form;
        form[key] = val
        this.setState({
            form
        })
    }
    render(){
        return(
            <div className="login">
                <WingBlank size="lg">
                        <Card>
                            <Card.Header title="欢迎登录"/>
                            <Card.Body>
                                <List>
                                    <InputItem placeholder="用户名" onChange={value => this.handleChange('userName', value)}>
                                        <i className="iconfont iconrenshu"></i>
                                    </InputItem>
                                    <InputItem placeholder="密码" type="password" onChange={value => this.handleChange('passWord',value)}>
                                        <i className="iconfont icondataopen"></i>
                                    </InputItem>
                                    <WhiteSpace />
                                    <div align="center">
                                    <Button type="primary" inline style={{ marginRight: '10px' }} onClick={this.submitLogin}>大数据局登录</Button>
                                    <Button type="primary" inline  onClick={this.submitLogin}>业务部门登录</Button>
                                    </div>
                                    <div align="center" style={{ margin: '10px 0' }}>
                                        <a href='#' style={{ margin: '0 5px' ,color: '#249AF2'}}>自主注册</a>|
                                        <a href='#' style={{ margin: '0 5px' ,color: '#249AF2'}}>忘记密码</a>|
                                        <a href='#' style={{ margin: '0 5px' ,color: '#249AF2'}}>问题帮助</a>
                                    </div>
                                </List>
                            </Card.Body>
                        </Card>
                </WingBlank>
            </div>
        )
    }
}


export default withRouter(Login);